package com.basic.modules.ykf.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import com.basic.common.utils.ParamsModel;
import com.basic.common.utils.ParamUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.basic.common.utils.PageUtils;
import com.basic.common.utils.Query;

import com.basic.modules.ykf.dao.YkfVideoManageDao;
import com.basic.modules.ykf.entity.YkfVideoManageEntity;
import com.basic.modules.ykf.service.YkfVideoManageService;


@Service("ykfVideoManageService")
public class YkfVideoManageServiceImpl extends ServiceImpl<YkfVideoManageDao, YkfVideoManageEntity> implements YkfVideoManageService {

    @Override
    public PageUtils queryPage(ParamsModel<YkfVideoManageEntity> params) {
        if (ObjectUtil.isEmpty(params.getSort()) || StrUtil.isBlank(params.getSort().getSidx()) || StrUtil.isBlank(params.getSort().getOrder())) {
            ParamsModel.SortParams sortParams = new ParamsModel.SortParams();
            sortParams.setSidx("createTime");
            sortParams.setOrder("desc");
            params.setSort(sortParams);
        }
        QueryWrapper<YkfVideoManageEntity> queryWrapper = ParamUtils.createQueryWrapperByDefaultSort(params);
        IPage<YkfVideoManageEntity> page = this.page(
                new Query<YkfVideoManageEntity>().getPage(BeanUtil.beanToMap(params.getPage())),
                queryWrapper
        );
        return new PageUtils(page);
    }
}
